﻿using DBController;
using RRQMSocket.RPC;
using TransferModels;

namespace WeChatService
{
    public class LoginServer : WeChatServer
    {
        [RRQMRPCMethod]
        public string Test(string mes)
        {
            return mes;
        }

        /// <summary>
        /// 注册账号
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [RRQMRPCMethod]
        public RegistAccountResult RegistAccount(RegistAccountRequest request)
        {
            RegistAccountResult result = new RegistAccountResult();

            string mes;
            if (Controller.AccountDB.Register(request.Account, request.Password, out mes))
            {
                result.Status = true;
            }
            else
            {
                result.Message = mes;
            }
            return result;
        }
        
        /// <summary>
        /// 验证登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [RRQMRPCMethod]
        public ConfirmLoginResult ConfirmLogin(ConfirmLoginRequest request)
        {
            ConfirmLoginResult result = new ConfirmLoginResult();

            if (Controller.AccountDB.Login(request.Account, request.Password))
            {
                result.Status = true;
            }
            else
            {
                result.Message = "账号或密码错误";
            }
            return result;
        }
        
        /// <summary>
        /// 查找好友
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [RRQMRPCMethod]
        public SearchFriendResult SearchFriend(SearchFriendRequest request)
        {
            SearchFriendResult result = new SearchFriendResult();
            UserInfo user = Controller.AccountDB.GetUserinfo(request.SearchAccount);
            if (user!=null)
            {
                result.UserInfo = user;
                result.Status = true;
            }
            else
            {
                result.Message = "账号或密码错误";
            }
            return result;
        }


    }
}